package com.ruoyi.driver.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.model.LoginDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.driver.domain.VehicleDriver;
import com.ruoyi.driver.service.IVehicleDriverService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 司机管理Controller
 * 
 * @author ruoyi
 * @date 2023-06-26
 */
@RestController
@RequestMapping("/driver")
public class VehicleDriverController extends BaseController
{
    @Autowired
    private IVehicleDriverService vehicleDriverService;

    /**
     * 查询司机管理列表
     */
    @RequiresPermissions("driver:driver:list")
    @GetMapping("/list")
    public TableDataInfo list(VehicleDriver vehicleDriver)
    {
        startPage();
        List<VehicleDriver> list = vehicleDriverService.selectVehicleDriverList(vehicleDriver);
        return getDataTable(list);
    }

    /**
     * 导出司机管理列表
     */
    @RequiresPermissions("driver:driver:export")
    @Log(title = "司机管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehicleDriver vehicleDriver)
    {
        List<VehicleDriver> list = vehicleDriverService.selectVehicleDriverList(vehicleDriver);
        ExcelUtil<VehicleDriver> util = new ExcelUtil<VehicleDriver>(VehicleDriver.class);
        util.exportExcel(response, list, "司机管理数据");
    }

    /**
     * 获取司机管理详细信息
     */
    @RequiresPermissions("driver:driver:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vehicleDriverService.selectVehicleDriverById(id));
    }

    /**
     * 新增司机管理
     */
    @RequiresPermissions("driver:driver:add")
    @Log(title = "司机管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleDriver vehicleDriver)
    {
        return toAjax(vehicleDriverService.insertVehicleDriver(vehicleDriver));
    }

    /**
     * 修改司机管理
     */
    @RequiresPermissions("driver:driver:edit")
    @Log(title = "司机管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleDriver vehicleDriver)
    {
        return toAjax(vehicleDriverService.updateVehicleDriver(vehicleDriver));
    }

    /**
     * 删除司机管理
     */
    @RequiresPermissions("driver:driver:remove")
    @Log(title = "司机管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vehicleDriverService.deleteVehicleDriverByIds(ids));
    }

    /**
     *根据手机号查询用户是否存在
     */
    @GetMapping("getDataByMobile/{mobile}")
    public LoginDriver getDataByMobile(@PathVariable String mobile){
        return vehicleDriverService.getDataByMobile(mobile);
    }

    @PostMapping("register")
    public LoginDriver register(@RequestBody LoginDriver loginDriver){
        return vehicleDriverService.register(loginDriver);
    }
}
